package sample.mybatis;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;

import sample.mybatis.domain.DeviceBind;
import sample.mybatis.mapper.DeviceBindMapper;

@Controller
@EnableAutoConfiguration
public class DeviceController {
	
	@Autowired
	private DeviceBindMapper deviceBindMapper;
	
	@GetMapping("/")
	@ResponseBody
	@Transactional(readOnly = true)
	public DeviceBind helloWorld() {
		return deviceBindMapper.selectByUserCode("10000046");
	}
	
	@GetMapping("/page/{cuurPage}")
	@ResponseBody
	@Transactional(readOnly = true)
	public List<DeviceBind> getUser(@PathVariable int cuurPage) {
		PageHelper.startPage(cuurPage, 2);
		return deviceBindMapper.getAllDeviceBinds();
	}
	
	public static void main(String[] args) {
		SpringApplication.run(DeviceController.class);
	}

}
